package cn.com.czpb.client.module.personal.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import cn.com.czpb.client.R;
import cn.com.czpb.client.model.news.NewsBean;
import cn.com.czpb.client.model.usercenter.CollectBean;
import cn.com.czpb.client.utils.StringUtils;

import java.util.List;


public class CollectionAdapter extends BaseMultiItemQuickAdapter<CollectBean, BaseViewHolder> {
    private String type;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CollectionAdapter(List<CollectBean> data, String type) {

        super(data);
        this.type = type;
        addItemType(NewsBean.LEFTPIC, R.layout.news_list_item_layout);
        addItemType(NewsBean.NOPIC, R.layout.news_list_item_nopic_layout);
        addItemType(NewsBean.BIGPIC, R.layout.news_list_bigitem_layout);
        addItemType(NewsBean.THREEPIC, R.layout.news_3_item_layout);

    }

    @Override
    protected void convert(BaseViewHolder helper, CollectBean item) {

        helper.setText(R.id.newsitem_title, item.getData().getTitle());//title
        helper.setText(R.id.newsitem_copyfrom, item.getData().getCopyfrom());
        helper.setText(R.id.comment_num_id, item.getData().getComcount() + "跟帖");//评论数量
        helper.setText(R.id.tv_time_id, item.getData().getUpdateTime());//时间

        if (!StringUtils.isEmpty(item.getData().getNewsflag())){
            helper.setVisible(R.id.img_newstype_id,true);
            helper.setText(R.id.img_newstype_id, item.getData().getNewsflag());//title
        }else{
            helper.setVisible(R.id.img_newstype_id,false);
        }

        helper.setText(R.id.newsitem_copyfrom, item.getData().getCopyfrom());
        switch (helper.getItemViewType()) {
            case NewsBean.THREEPIC:
                helper.setText(R.id.praise_num_id,item.getData().getPraisecount());//点赞数
                if (type.equals("0")) {
                    if (item.getData().getImgs().size()>0){
                        Glide.with(mContext).load(item.getData().getImgs().get(0)).into((ImageView) helper.getView(R.id.news_3_item1));
                        Glide.with(mContext).load(item.getData().getImgs().get(1)).into((ImageView) helper.getView(R.id.news_3_item2));
                        Glide.with(mContext).load(item.getData().getImgs().get(2)).into((ImageView) helper.getView(R.id.news_3_item3));
                    }

                }
                helper.addOnClickListener(R.id.newsItem_root);

                break;
            case NewsBean.LEFTPIC:
                helper.setText(R.id.praise_num_id,item.getData().getPraisecount());//点赞数
                if (!item.getData().getRtype().equals("6")){
                    helper.getView(R.id.img_play_id).setVisibility(View.GONE);
                }
                if (type.equals("0")) {
                    if (item.getData().getImgs().size()>0) {
                        Glide.with(mContext).load(item.getData().getImgs().get(0)).into((ImageView) helper.getView(R.id.newsitem_img));
                    }
                }
                helper.setText(R.id.newsitem_title, item.getData().getTitle())
                        .addOnClickListener(R.id.newsItem_root)
                ;
                break;
            case NewsBean.NOPIC:
                helper.setText(R.id.praise_num_id,item.getData().getPraisecount());//点赞数
                helper.setText(R.id.newsitem_title, item.getData().getTitle())
                        .addOnClickListener(R.id.newsItem_root);
                break;
            case NewsBean.BIGPIC:
                helper.setText(R.id.praise_num_id,item.getData().getPraisecount());//点赞数
                if (!item.getData().getRtype().equals("6")){
                    helper.getView(R.id.img_play_id).setVisibility(View.GONE);
                }
                if (type.equals("0")) {
                    if (item.getData().getImgs().size()>0) {
                        Glide.with(mContext).load(item.getData().getImgs().get(0)).into((ImageView) helper.getView(R.id.newsitem_img));
                    }
                }
                helper.setText(R.id.newsitem_title, item.getData().getTitle())
                        .addOnClickListener(R.id.newsItem_root);
                break;
        }
    }


}
